<?php
namespace Admin\Controller;
use Think\Controller;

/** 
 * use Common\Model 这块可以不需要使用，框架默认会加载里面的内容
 */
class LoginController extends Controller {

    public function index(){
        if(session('adminUser')){
            $this->redirect('/index.php?m=admin&c=index');
        }
    	 $this->display();
    }
    public function check(){
        $username = trim($_POST['username']);
        $password = trim($_POST['password']);
        if(empty($username)){
         return show( 0 , '用户名不能为空');
        }
        if(empty($password)){
         return show( 0 , '密码不能为空');
        }
        $ret = D('Admin')->getAdminByUsername($username);
        if(!$ret['username']){
            return show(0, '用户不存在');
        }
        if($ret['password'] != getMd5Password($password)){
            return show( 0, '密码错误');
        }
        session('adminUser' , $ret);
        return show( 1, "登录成功");
    }
    public function Loginout(){
        session('adminUser' , null);
        $this->redirect('/index.php?m=admin&c=login');
    }
}